package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.Grow;
import com.ruoyi.system.service.IGrowService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 成长记录Controller
 * 
 * @author ruoyi
 * @date 2025-02-19
 */
@RestController
@RequestMapping("/grow")
public class GrowController extends BaseController
{
    @Autowired
    private IGrowService growService;

    /**
     * 查询成长记录列表
     */
    @RequiresPermissions("system:grow:list")
    @GetMapping("/list")
    public TableDataInfo list(Grow grow)
    {
        startPage();
        List<Grow> list = growService.selectGrowList(grow);
        return getDataTable(list);
    }

    /**
     * 导出成长记录列表
     */
    @RequiresPermissions("system:grow:export")
    @Log(title = "成长记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Grow grow)
    {
        List<Grow> list = growService.selectGrowList(grow);
        ExcelUtil<Grow> util = new ExcelUtil<Grow>(Grow.class);
        util.exportExcel(response, list, "成长记录数据");
    }

    /**
     * 获取成长记录详细信息
     */
    @RequiresPermissions("system:grow:query")
    @GetMapping(value = "/{growId}")
    public AjaxResult getInfo(@PathVariable("growId") Long growId)
    {
        return success(growService.selectGrowByGrowId(growId));
    }

    /**
     * 新增成长记录
     */
    @RequiresPermissions("system:grow:add")
    @Log(title = "成长记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Grow grow)
    {
        return toAjax(growService.insertGrow(grow));
    }

    /**
     * 修改成长记录
     */
    @RequiresPermissions("system:grow:edit")
    @Log(title = "成长记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Grow grow)
    {
        return toAjax(growService.updateGrow(grow));
    }

    /**
     * 删除成长记录
     */
    @RequiresPermissions("system:grow:remove")
    @Log(title = "成长记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{growIds}")
    public AjaxResult remove(@PathVariable Long[] growIds)
    {
        return toAjax(growService.deleteGrowByGrowIds(growIds));
    }
}
